from common.api import Api
from common.read import read
from common.response import process_response
from testcase.usercenter import conftest

class UserApi(Api):

    #注册页面输入手机号发送验证码
    def send_code(self,**kwargs):
        json_data= read.read_yaml()['test_register']
        res = self.post('/code/',json=json_data)
        if res.status_code == 400:
            conftest.delete_code(json_data['mobile'])
            res = self.post('/code/', json=json_data)
        return res

    #注册并登录接口
    def register_login(self,code,mobile):
        json_data = {
            "code": code,
            "password": "123456",
            "username": mobile
        }
        res = self.post("/users/",json=json_data)
        assert res.status_code == 200
        return res

    #首页banner接口
    def banners(self,headers):
        res = self.get('/banners/',headers = headers)
        assert res.status_code == 200
        return res

    #会员中心-我的留言/投诉/咨询/售后/求购新增接口
    def messages(self,data,headers):
        files = read.read_img()
        res = self.post('/messages/',data = data ,files = files,headers=headers)
        assert res.status_code == 201
        return res

    #会员中心-删除我的留言/投诉/咨询/售后/求购接口
    def delete_message(self,id,headers):
        res = self.delete('/messages/%s/'%id ,headers=headers)
        assert res.status_code == 204

    #会员中心-查看我的留言/投诉/咨询/售后/求购接口
    def messages_info(self,headers):
        res = self.get('/messages/',headers=headers)
        assert res.status_code == 200
        return res

userapi = UserApi()
